function addAdminArea(){
	$.fn.tree.getSelect();
	var id=$.fn.tree.tmpid;
	var level=getLevel();
	if(id==undefined || id=="" || id=="0" || id==0){
		easyDialog.open({
			container:{
				header:"温馨提示",
				content:"请选择要操作的记录！"
			},
			autoClose : 2000
		});
		return;
	}
	if(level==6){
		easyDialog.open({
			container:{
				header : '温馨提示',
				content:"该级区域不能添加！"
			},
			autoClose : 2000
		});
		return;
	}
	var token=localStorage.getItem("token");
	$('#administrtionOutTree').remove();
	$.ajax({
		url:server_url+'areaManager/addAdminTreeStep1.do?ran='+Math.random()+'&token='+token,
		type:'get',
		data: {id:id,level:level},
		success:function(data){
			var html='<div class="z_rightMidden">'
				+'<div class="z_title">首页>行政区域管理>添加区域</div>'
				+'<div class="l_system">'
				+'<ul>'
				+'<li class="clearfix">'
				+'<span>区域名称</span>'
				+'<input type="text" id="areaName" onkeyup="checkAreaName();" maxlength="30"/>'
				+'<em>*</em>'+'<em id="tishi" style="margin:0px 0 0 0px;"></em>'
				+'</li>'
				+'<li class="clearfix">'
				+'<span>地区</span>'
				+'<div class="l_adress">';
			if(level==1||level==2||level==3||level==4||level==5){
				//只选中中国下
				html+='<span>中国</span>';
			}
			if(level==2||level==3||level==4||level==5){
				//选择省下
				html+='<em>></em><span>'+data.data.shengName+'</span>';
			}
			if(level==3||level==4||level==5){
				//选择市下
				html+='<em>></em><span>'+data.data.shiName+'</span>';
			}
			if(level==4||level==5){
				//选择县下
				html+='<em>></em><span>'+data.data.xianName+'</span>';
			}
			if(level==5){
				//选择镇下
				html+='<em>></em><span>'+data.data.zhenName+'</span>';
			}
			html+='</div>'
				+'</li>'
				+'<li class="clearfix">'
				+'<span>区域代码</span>'
				+'<div>';
			if(level==1||level==2||level==3){
				html+='<input type="text" id="areaCode" maxlength="6" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"/>'
			}
			if(level==4||level==5){
				html+='<input type="text" id="areaCode" maxlength="12" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" onafterpaste="this.value=this.value.replace(/\\D/g,\'\')"/>'
			}
			html+='</div>'
				+'</li>'
				+'<li class="clearfix">'
				+'<span>备注</span>'
				+'<textarea name="" id="areaDesc" cols="30" rows="10" maxlength="100"></textarea>'
				+'</li>'
				+'</ul>'
				+'<a href="javascript:addSubmit();" class="z_sure">确定</a>'
				+'<a href="javascript:returnList();" class="z_goback">返回</a>'
				+'</div>'
				+'</div>';
			$('#administrtionTreeAdd').html(html);

		}
	});

}

function getId(){
	return $.fn.tree.getSelect();
};
function getParentId(){
	return $.fn.tree.obj_tu.parentId;
};
function getLevel(){
	return $.fn.tree.obj_tu.level;
};

function addSubmit(){
	$.fn.tree.getSelect();
	var id=$.fn.tree.tmpid;
	var areaName=$("#areaName").val();
	var areaCode=$("#areaCode").val();
	var areaDesc=$("#areaDesc").val();
	var parentId=getParentId();
	var username=localStorage.getItem("username");
	var level=getLevel();
	var reg = /^([0-9.]+)$/;
	if(areaName=="" || areaName==undefined){
		$("#tishi").text("该值不能为空");
		return;
	}
	if(areaCode!=null && areaCode!="" && areaCode !=undefined){
		if(reg.test(areaCode) != true){
			easyDialog.open({
				container:{
					header : '温馨提示',
					content:"区域代码只能为数字！"
				},
				autoClose : 2000
			});
			return;
		}
		isExistAreaCode(null,areaCode);
	}
	var isExist = $("#isExist").val();
	if(isExist=="1"){
		easyDialog.open({
			container:{
				header : '温馨提示',
				content:"区域代码不能相同！"
			},
			autoClose : 2000
		});
		return;
	}
	var token=localStorage.getItem("token");
	$.ajax({
		url:server_url+'areaManager/addAdminTreeStep2.do?ran='+Math.random()+'&token='+token,
		type:'post',
		async:false,
		data: {id:id,parentId:parentId,level:level,areaCode:areaCode,areaDesc:areaDesc,areaName:areaName,username:username},
		success:function(data){
			back();
		}
	});
}
function returnList(){
	back();
}
function back(){
	tl_config.loadToWorkArea("showAdminAreaPage.do?ran="+Math.random());
}

function isExistAreaCode(id,areaCode){
	$.ajax({
		url:server_url+'areaManager/isExistAdminAreaCode.do?ran='+Math.random()+'&token='+token,
		type:'post',
		async:false,
		data: {id:id,areaCode:areaCode},
		success:function(data){
			if(data.retCode == '0002'){
				$("#isExist").val("1");
			}
			if(data.retCode == '0000'){
				$("#isExist").val("0");
			}
		}
	});
}


function checkAreaName(){
	var areaName=$("#areaName").val();
	if(areaName=="" || areaName==undefined){
		$("#tishi").text("该值不能为空");
	}else{
		$("#tishi").text("");
	}
}


